package InternetProgram;

import com.sun.javafx.image.BytePixelSetter;

import java.io.*;
import java.net.*;
/**
 * @ClassName: ProgramC
 * @Auther: Drawin
 * @Date: 2021/11/22 16:56
 * @Description:
 */

public class ProgramC {
    public static void main(String[] args) {
        try {
            Socket s = new Socket("localhost",3000);
            System.out.println("已经连接到ProgramD");
            ProgramReceive pr=new ProgramReceive(s);
            pr.start();
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            DataOutputStream dout = new DataOutputStream(s.getOutputStream());
            while (true){
                String mytmp =br.readLine();
                if(dout!=null)//dout不为空，说明还能发送
                dout.writeUTF(mytmp);
                else//dout为空，说明不能发送数据了
                break;
                if (mytmp.trim().equals("bye")){
                    if (dout!=null) dout.close();
                    if (s!=null) s.close();
                    if(br!=null) br.close();
                    break;
                }
            }
        }catch (UnknownHostException e){
            System.out.println("连接服务器失败："+e.getMessage());
        }catch (IOException e){
            System.out.println("发送数据失败："+e.getMessage());
        }
    }
}
